package ASSET.RESOURCE;

import java.net.InetAddress;
import java.net.UnknownHostException;

import TOOLS.SQLtool;
import TOOLS.errCodeManagement;
import WORKPLACE.c_autoUpdateTool;

public class test002_newDB {

	public static void main(String[] args) {
		SQLtool sql=new SQLtool();
		String IPaddr="192.168.1.1";
		try {
			InetAddress addr = InetAddress.getLocalHost();
			IPaddr=addr.getHostAddress();
		} catch (UnknownHostException e1) {
			;
		}
		sql.config(IPaddr, "AKS2019", "sa", "123456");
//		sql.config("10.130.0.231", "Smes", "sa", "led-00");
//		sql.config("10.130.1.9", "Smes", "root", "led-123@");
		sql.config("172.16.3.115", "XHAKS2021", "ma", "123456");
		try {
			sql.connect();
//			c_resource c=new c_resource(sql);
//			c.newDBsheet();
//			c.newDBview();
			
			String tableName="[dbo].[fixtureInfo]";
			String sqlStr="IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL DROP TABLE "+tableName;
			tableName="[dbo].[resourceList_panel]";
			sqlStr="IF OBJECT_ID('"+tableName+"', 'U') IS NOT NULL DROP TABLE "+tableName;
			try {
				sql.Command(sqlStr);
			} catch (Exception e) {
				if(e.getMessage().equals("-11")) {
					;
				}else {
					throw e;
				}
			}
			sqlStr="CREATE TABLE "+tableName+" (\r\n" + 
					"[resourceListPanelIndex] int IDENTITY(1,1) NOT NULL UNIQUE,\r\n" + 
					"[panelNumber] varchar(50) NOT NULL ,\r\n" + 
					"[layer] int DEFAULT 1 ,\r\n" + 
					"[resourceName] varchar(100) NULL ,\r\n" + 
					"[createTime] datetime DEFAULT GETDATE() ,\r\n" + 
					"[lastTime] datetime DEFAULT GETDATE() \r\n" + 
					")";
			sql.Command(sqlStr);
			
		} catch (Exception e) {
			String str=errCodeManagement.getErrText(e.getMessage());
			System.out.println(str);
		}
	}

}
